package com.example.juyixia;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapterchecked extends BaseAdapter {
	private List<Map<String, Object>> data;
    private LayoutInflater layoutInflater;
    private Context context;
    List<Boolean> mChecked;  
    public MyAdapterchecked(Context context, List<Map<String, Object>> data) {
    //传入的data，就是我们要在listview中显示的信息
        this.context = context;
        this.data = data;
        this.layoutInflater = LayoutInflater.from(context);
        mChecked = new ArrayList<Boolean>();  
        for(int i=0;i<data.size();i++){  
            mChecked.add(false); 
            }
    }
    //这里定义了一个类，用来表示一个item里面包含的东西，像我的就是一个imageView和三个TextView，按自己需要来
    public class Info {
        public ImageView image;
        public TextView username;
        public TextView userid;
        public CheckBox ischecked;
    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		 return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		 return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		 Info info = new Info();
	        convertView = layoutInflater.inflate(R.layout.item_newact_checkfriend, null);
	        info.image = (ImageView) convertView.findViewById(R.id.headpic);
	        info.userid = (TextView) convertView
	                .findViewById(R.id.usersfriendid);
	        info.username = (TextView) convertView
	                .findViewById(R.id.usersfriendname);
            info.ischecked=(CheckBox)convertView.findViewById(R.id.friendchecked);
	        //设置数据
	        info.image.setImageResource((Integer) data.get(position).get("image"));
	        info.userid.setText((String) data.get(position).get(
	                "userid"));
	        info.username.setText((String) data.get(position).get(
	                "username"));
	        info.ischecked.setChecked(mChecked.get(position));
	        return convertView;
	}

}

